Release 10.1A: OpenEdge Development:
Web Services


Complex data example

The following examples show how you might manage a complex parameter, or any complex data, in this case, an OUTPUT parameter as serialized XML. This is a procedure that maps to a Web service operation, getAddress. Given a social security number (ssn), the operation returns an address (Address) as a complex type:

4GL prototype with a complex parameter accessed as serialized XML
PROCEDURE getAddress: 
  DEFINE INPUT PARAMETER ssn AS CHARACTER. 
  DEFINE OUTPUT PARAMETER Address AS LONGCHAR. 
END PROCEDURE. 

This is the schema for a <complexType> element that returns the address information to the caller. It contains five string data type elements representing the components of the address:

Complex type in the WSDL
<complexType name="Address"> 
   <sequence> 
      <element name="name" type="xsd:string"> 
      <element name="street" type="xsd:string"> 
      <element name="city" type="xsd:string"> 
      <element name="state" type="xsd:string"> 
      <element name="zip-code" type="xsd:string"> 
   </sequence> 
</complexType> 

This sample 4GL procedure demonstrates how you can manage this complex type in the 4GL as a DOM tree. The variable to receive the parameter value, cmAddress, is defined as a LONGCHAR, which is essentially a CHARACTER-compatible MEMPTR. After the Web service operation returns a value for cmAddress, the LOAD( ) method on the x-document handle, hXDoc, parses and loads the <complexType> element from cmAddress into the associated x-document object.

Because the schema of the complex type is known, the remaining x-document and x-noderef handle methods simply retrieve the root node from the “Address” DOM tree, and pick off the component value (text element) for each of the five component nodes that comprise the complex type, in order, assigning them to the corresponding fields of a database record.

Note: The URL for the Web service in the following example is completely fictitious, and any resemblance to an actual public Web service is coincidental.

This is the 4GL example for handling the parameter as a DOM tree:

Complex type managed in the 4GL as a DOM tree
DEFINE VARIABLE hWS AS HANDLE. 
DEFINE VARIABLE hAddrPortType AS HANDLE. 
DEFINE VARIABLE cmAddress AS LONGCHAR. 
CREATE SERVER hWS. 
hWS:CONNECT ("-WSDL http://www.zzzcompany.org/ssn.wsdl 
              -Service addressSVC 
              -Port addressPort"). 
RUN addressPortType SET hAddrPortType ON SERVER hWS. 
RUN getAddress IN hAddrPortType (INPUT "555-55-5555", OUTPUT cmAddress). 
DEFINE VARIABLE hXDoc as HANDLE. 
DEFINE VARIABLE hXRoot as HANDLE. 
DEFINE VARIABLE hXNode as HANDLE. 
DEFINE VARIABLE hXText as HANDLE. 
CREATE X-DOCUMENT hXDoc. 
CREATE X-NODEREF hXRoot. 
CREATE X-NODEREF hXNode. 
CREATE X-NODEREF hXText. 
hXDoc:LOAD("LONGCHAR", cmAddress, FALSE). 
hXDoc:GET-DOCUMENT-ELEMENT(hXRoot). 
/* because we know the content, we are just moving straight ahead 
   and getting each one of the nodes under the root, then getting its  
   TEXT node to get the data we're interested in. */ 
hXRoot:GET-CHILD(hXNode, 1). 
hXNode:GET-CHILD(hXText, 1). 
/* let's assume we have a DB table with the appropriate fields */ 
myTable.name = hXText:NODE-VALUE. 
/* ... */ 
hXRoot:GET-CHILD(hXNode, 5). 
hXNode:GET-CHILD(hXText, 1). 
myTable.zip-code = hXText:NODE-VALUE. 
/* clean up */ 
/* ...      */ 
hWS:DISCONNECT( ). 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095